package com.xyht.medicine_management_system.modules.classification.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.annotation.RequestPass;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.classification.entity.req.MmsMedicineClassificationAddReq;
import com.xyht.medicine_management_system.modules.classification.entity.req.MmsMedicineClassificationDeletedReq;
import com.xyht.medicine_management_system.modules.classification.entity.req.MmsMedicineClassificationUpdateReq;
import com.xyht.medicine_management_system.modules.classification.service.MmsMedicineClassificationService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 药品分类 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-11-29
 */
@RestController
@SecretBody
@RequestMapping("/classification")
public class MmsMedicineClassificationController {

    @Resource
    private MmsMedicineClassificationService mmsMedicineClassificationService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("添加分类")
    @PostMapping("/add")
    public ResponseResult addClassification(@RequestBody MmsMedicineClassificationAddReq addReq){
        return mmsMedicineClassificationService.addClassification(addReq);
    }

    @ApiModelProperty("修改分类")
    @PostMapping("/update")
    public ResponseResult updateClassification(@RequestBody MmsMedicineClassificationUpdateReq updateReq){
        return mmsMedicineClassificationService.updateClassification(updateReq);
    }

    @ApiModelProperty("删除分类")
    @PostMapping("/deleted")
    public ResponseResult deletedClassification(@RequestBody MmsMedicineClassificationDeletedReq deletedReq){
        return mmsMedicineClassificationService.deletedClassification(deletedReq.getId());
    }

    @ApiModelProperty("查看分类详情")
    @GetMapping("/id")
    public ResponseResult getClassificationDetail(@RequestParam("id") String id, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsMedicineClassificationService.getClassificationDetail(id,userId);
    }

    @ApiModelProperty("查看分类列表")
    @GetMapping("/list")
    @RequestPass
    public ResponseResult getClassificationList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam(value = "name",required = false) String name,
                                                @RequestParam(value = "type",required = false) Integer type,
                                                HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdOrNullByRequest(request);
        return mmsMedicineClassificationService.getClassificationList(pageNum,pageSize,name,userId,type);
    }

}

